<template>
	<section class="aui-flexView">
		
		<section class="aui-scrollView">
			<view class="aui-tab" data-ydui-tab>
				<view class="xiao">

				</view>
				<!-- 订单状态导航栏 -->
				<ul class="tab-nav">
					<block v-for="(menuTab,index) in menuTabs" :key="index">
						<li v-bind:id="'tabNum'+index" @click="swichMenu(index)" :class="[title_type==index ? 'tab-nav-item tab-active' : 'tab-nav-item']">
							{{menuTab.name}}
						</li>
					</block>
				</ul>
				<view class="xian"></view>
				<view class="divHeight"></view>
				<view class="tab-panel">
					<block v-for="(menuList,index2) in menuTabs" :key="index2">
						<view :class="[title_type==index2 ? 'tab-panel-item tab-active' : 'tab-panel-item']">
							<!-- 页面中的商品 -->
							<block v-for="(menuList2,index3) in menuLists" :key="index3">
								<view class="tab-item">
									<a href="javascript:void(0);" class="aui-well-item aui-well-item-clear">
										<!-- 商家logo位置 -->
										<view class="aui-well-item-hd">
											
										</view>
										<!-- 商家名字 -->
										<view class="aui-well-item-bd">
											<!-- <h3>{{menuList2.comp_name}}</h3> -->
										</view>
										<!-- 订单状态，是否取消 -->
										<span class="aui-well-item-fr"></span>
									</a>
									<view class="six"></view>
									<!-- 单个商家中购买的物品 -->
									<view class="aui-mail-product"  v-for="(menuList3,index4) in menuList2.product" :key="index4">
										<a href="javascript:;" class="aui-mail-product-item">
											<view class="aui-mail-product-item-hd">
												<img :src="wz+menuList3.pimg" alt="">
											</view>
											<view class="aui-mail-product-item-bd">
												<p>{{menuList3.pname}}</p>
											</view>
											<view class="money">
												<p>￥{{menuList3.price}}</p>
											</view>
										</a>
									</view>
									<view class="six"></view>
									<view class="dibu">
										<view class="aui-mail-payment">
											<span style="width: 60%; overflow: hidden;
 text-overflow: ellipsis;
 white-space: nowrap;">共{{menuList2.product.length}}件商品 实付款: ￥{{menuList2.paymoney}}</span>
											<p class="yunfai">(含运费：0)</p>
											<view class="seven"></view>
										</view>
										<view v-if="title_type==1 ">
											<view class="quxiao" @tap="call_off(menuList2.id)">取消订单</view>
										</view>
										<view class="tiao"></view>
									</view>

								</view>
								<view class="tou">
									<!-- 改动位置 -->
									<view class="aui-mail-button">
										<a href="javascript:;" @tap="queren1(menuList2.id)" :class="[title_type == 2 || title_type == 3 ? '' : 'hd']">确认收货</a>
										<a href="javascript:;" @tap="queren2(menuList2)" :class="[title_type != 1 && title_type != 2 && title_type != 3? '':'hd']">再次购买</a>
										<a href="javascript:;" @tap="queren3(menuList2)" :class="[title_type ==1 ? '' :'hd']">订单支付</a>   

									</view>
									<!-- 改动位置结尾 -->
								</view>
								<view :class="[index3+1==menuList.length ? 'hd':'divHeight']"></view>

							</block>
						</view>
					</block>
				</view>
			</view>
		</section>
	</section>
</template>

<script>
	export default {
		data() {
			return {
				title_type:'',
				scrollLeft: 0,
				isClickChange: false,
				currentTab: 0,
				type:'',
				wz:'http://tuiguang.yiyunoto.com',
				menuTabs: [{
					name: '全部'
				}, {
					name: '待付款'
				}, 
				{
					name: '待发货'
				}, {
					name: '待收货'
				}, {
					name: '已完成'
				}, {
					name: '退货中'
				}, ],
				menuLists: [
			
				]
			}
		},
		onLoad(options) {
			// for (var i = 0; i < this.menuLists.length; i++) {
			// 	this.getDateList(i);
			// }
			console.log("获取id",options.num)
			this.title_type=options.num
			const id=options.id
			uni.showLoading({
			    title: '拼命加载中'
			});
			this.order_data()
		},
		onShow() {
			this.swichMenu(this.title_type)
		}
		,
		methods: {
			onPullDownRefresh: function() {
				this.order_data()
				},
		order_data(){ 
			uni.request({
					url:'http://tuiguang.yiyunoto.com/api/member/memorder',
					header:{authtoken:this.$store.state.token},
					method:'POST',
					data:{status:this.type},
					success:(res)=>{
						console.log("请求成功",res)
						this.menuLists = res.data.data
						uni.hideLoading();
						 uni.stopPullDownRefresh();
					},
					fail:(res)=>{
						console.log("请求失败",res)
					}
				})
			},
			call_off(e){
				console.log("取消",e)
				uni.request({
					url:'http://tuiguang.yiyunoto.com/api/member/cancle',
					header:{authtoken:this.$store.state.token},
					method:'POST',
					data:{oid:e},
					success:(res)=>{
						console.log("请求成功",res)
						this.$api.msg(res.data.msg);
						this.order_data()
					},
					fail:(res)=>{
						console.log("请求失败",res)
					}
				})
			},
			//确认收货
			queren1:function(e){
				
				console.log("121")
				uni.request({
					url:'http://tuiguang.yiyunoto.com/api/member/confirm',
					header:{authtoken:this.$store.state.token},
					method:'POST',
					data:{oid:e},
					success:(res)=>{
						console.log("请求成功",res)
						this.$api.msg(res.data.msg);
						this.order_data()
					},
					fail:(res)=>{
						console.log("请求失败",res)
					}
				})
			},
			queren2:function(menuList){
				console.log("1212")
				uni.showToast({
					title:"请前往购物车购买",
					icon:"none"
				})
			},
			queren3:function(e){
				console.log("1213" ,e)
				uni.showToast({
					title:"请前往购物车购买",
					icon:"none"
				})
				console.log("1" ,e.ordernum)
				console.log("1" ,e.ordernum.substring(0,1))
				if(e.ordernum.substring(0,1)=="Q"){
					this.$api.msg("该商品为抢购产品，请重新购买！")
				}
				else{
					this.$api.msg("该商品未能及时支付，请重新购买！")
					// let params = "freight=" +e.product[0].freight+ "&num=" + e.product[0].num+"&oid="+e.product[0].oid+"&pimg="+e.product[0].pimg+"&pname="+e.product[0].pname+"&price="+e.product[0].price;
					// console.log("12",params)
					// 	uni.navigateTo({
					// 		url:"../Order_details/index?"+params
					// })
				}
			},
			swichMenu: async function(current) { //点击其中一个选项
				if (this.currentTab == current) {
					return false;
				} else {
					this.currentTab = current;
					this.setScrollLeft(current);
				};
				console.log("点击数据",current)
				if(current==0){
					this.type=""
				}else{
					this.type=current
				}
				uni.request({
					url:'http://tuiguang.yiyunoto.com/api/member/memorder',
					header:{authtoken:this.$store.state.token},
					method:'POST',
					data:{status:this.type},
					success:(res)=>{
						console.log("请求成功",res)
						this.menuLists = res.data.data
					},
					fail:(res)=>{
						console.log("请求失败",res)
					}
				}),
				this.title_type=current
			},
			swiperChange: async function(e) {
				let index = e.target.current;
				this.setScrollLeft(index);
				this.currentTab = index;
			},
			setScrollLeft: async function(tabIndex) {
				let leftWidthSum = 0;
				for (var i = 0; i <= tabIndex; i++) {
					let nowElement = await this.getWidth('tabNum' + i);
					leftWidthSum = leftWidthSum + nowElement.width;
				}
				let winWidth = uni.getSystemInfoSync().windowWidth;
				this.scrollLeft = leftWidthSum > winWidth ? (leftWidthSum - winWidth) : 0
			},
			getWidth: function(id) { //得到元素的宽高
				return new Promise((res, rej) => {
					uni.createSelectorQuery().select("#" + id).fields({
						size: true,
						scrollOffset: true
					}, (data) => {
						res(data);
					}).exec();
				})
			},
			getDateList: function(tabIndex) {
				// var entity = this.menuTabs[tabIndex].name;
				// this.menuLists[tabIndex].push(entity);
			},
		}
	}
</script>

<style>
	/* 公共样式表css */
	html,
	body {
		color: #333;
		margin: 0;
		height: 100%;
		font-family: "Myriad Set Pro", "Helvetica Neue", Helvetica, Arial, Verdana, sans-serif;
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
		font-weight: normal;
	}

	* {
		-webkit-box-sizing: border-box;
		-moz-box-sizing: border-box;
		box-sizing: border-box;
	}

	a {
		text-decoration: none;
		color: #000;
	}

	a,
	label,
	button,
	input,
	select {
		-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
	}

	img {
		border: 0;
	}

	body {
		background: #fff;
		color: #666;
	}

	html,
	body,
	div,
	dl,
	dt,
	dd,
	ol,
	ul,
	li,
	h1,
	h2,
	h3,
	h4,
	h5,
	h6,
	p,
	blockquote,
	pre,
	button,
	fieldset,
	form,
	input,
	legend,
	textarea,
	th,
	td {
		margin: 0;
		padding: 0;
		float: left;
	}

	a {
		text-decoration: none;
		color: #08acee;
	}

	button {
		outline: 0;
	}

	img {
		border: 0;
	}

	button,
	input,
	optgroup,
	select,
	textarea {
		margin: 0;
		font: inherit;
		color: inherit;
		outline: none;
	}

	li {
		list-style: none;
	}

	a {
		color: #666;
	}
	.clearfix::after {
		clear: both;
		content: ".";
		display: block;
		height: 0;
		visibility: hidden;
	}
	.clearfix {}
	/* 必要布局样式css */
	.aui-flexView {
		width: 100%;
		height: 100%;
		margin: 0 auto;
		display: -webkit-box;
		display: -webkit-flex;
		display: -ms-flexbox;
		display: flex;
		-webkit-box-orient: vertical;
		-webkit-box-direction: normal;
		-webkit-flex-direction: column;
		-ms-flex-direction: column;
		flex-direction: column;

	}
	.aui-scrollView {
		width: 100%;
		height: 100%;
		-webkit-box-flex: 1;
		-webkit-flex: 1;
		-ms-flex: 1;
		flex: 1;
		overflow-y: auto;
		overflow-x: hidden;
		-webkit-overflow-scrolling: touch;
		position: relative;
		/* margin-top: -44px; */
	}
	.aui-navBar {
		height: 88upx;
		position: relative;
		display: -webkit-box;
		display: -webkit-flex;
		display: -ms-flexbox;
		display: flex;
		z-index: 1002;
		background: #ffffff;
	}
	.aui-navBar:after {
		content: '';
		position: absolute;
		z-index: 2;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 2upx;
		border-bottom: 1px solid #ffffff;
		-webkit-transform: scaleY(0.5);
		transform: scaleY(0.5);
		-webkit-transform-origin: 0 100%;
		transform-origin: 0 100%;
	}
	.aui-center {
		-webkit-box-ordinal-group: 3;
		-webkit-order: 2;
		-ms-flex-order: 2;
		order: 2;
		display: -webkit-box;
		display: -webkit-flex;
		display: -ms-flexbox;
		display: flex;
		-webkit-box-pack: center;
		-webkit-justify-content: center;
		-ms-flex-pack: center;
		justify-content: center;
		-webkit-box-align: center;
		-webkit-align-items: center;
		-ms-flex-align: center;
		align-items: center;
		height: 88upx;
		width: 50%;
		margin-left: 25%;
	}
	.aui-center-title {
		text-align: center;
		width: 100%;
		white-space: nowrap;
		overflow: hidden;
		display: block;
		text-overflow: ellipsis;
		font-size: 0.95rem;
		color: #3c3c3c;
		position: fixed;
		background: #FFFFFF;
		padding: 40upx;
	}
	.xiao {
		width: 100%;
		height: 1upx;
		background: #F0F2F5;
		margin-top: 10upx;
		position: fixed;
		display: block;
		z-index: 10000;
	}
	.tab-nav {
		background: #FFFFFF;
		height: 80upx;
		line-height: 80upx;
		/* border-radius: 80px; */
		display: block;
		/* margin: 0 auto; */
		position: fixed;
		width: 100%;
		margin-bottom: 15%;
		/* width: 185px; */
		z-index: 9999;
	}
	.tab-nav:after {
		content: '';
		position: fixed;
		z-index: 2;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 1upx;
		border-bottom: 1px solid #bbbbbb;
		-webkit-transform: scaleY(0.5);
		transform: scaleY(0.5);
		-webkit-transform-origin: 0 100%;
		transform-origin: 0 100%;
	}
	.tab-nav-item {
		height: 80upx;
		line-height: 80upx;
		position: relative;
		text-align: center;
		color: #585858;
		font-size: 0.9rem;
		display: block;
		float: left;
		border-radius: 160px;
		/* padding: 0 15px; */
		width: 16.5%;
		margin: 0 auto;
	}
	.tab-nav-item.tab-active {
		/* background-color: #51bd03; */
	}
	.tab-nav-item.tab-active a {
		color: #000000;
		font-weight: bold;
	}
	.tab-nav-item a {
		display: inherit;
		color: inherit;
		font-size: 0.8rem;
		color: #464646;
	}
	.tab-panel {
		position: relative;
		overflow: hidden;
	}
	.tab-panel .tab-panel-item {
		width: 100%;
		position: absolute;
		top: 0;
		-webkit-transform: translateX(-100%);
		transform: translateX(-100%);
	}
	.tab-nav-item.tab-active:before {
		content: '';
		width: 40%;
		height: 0px;
		position: absolute;
		left: 50%;
		bottom: 0;
		margin-left: -20%;
		z-index: 4;
		background-color: #f23030;
		border-radius: 240upx;
		border: 1px solid #42a8FF;
	}
	.tab-panel .tab-panel-item.tab-active~.tab-panel-item {
		-webkit-transform: translateX(100%);
		transform: translateX(100%);
	}
	.tab-panel .tab-panel-item.tab-active {
		position: relative;
		-webkit-transition: -webkit-transform .15s;
		transition: -webkit-transform .15s;
		transition: transform .15s;
		transition: transform .15s, -webkit-transform .15s;
		-webkit-transform: translateX(0);
		transform: translateX(0);
	}
	.xian {
		width: 100%;
		height: 2upx;
		background: #F0250F;
	}
	.divHeight {
		background: #F5F5F5;
		width: 100%;
		height: 20upx;
		padding-top: 40upx;
	}
	.aui-well-item {
		padding: 25px 15px 20px 20px;
		position: relative;
		display: -webkit-box;
		display: -webkit-flex;
		display: flex;
		-webkit-box-align: center;
		-webkit-align-items: center;
		align-items: center;
	}
	.six {
		width: 691upx;
		height: 2upx;
		background: #E9E9EC;
		margin: 0 auto;
	}
	.seven {
		width: 691upx;
		height: 2upx;
		background: #E9E9EC;
		margin: 0 auto;
		margin-top: 88upx;
	}
	.aui-well-item-hd {
		margin-right: .4em;
		width: 38upx;
		height: 38upx;
		line-height: 38upx;
		text-align: center;
	}
	.aui-well-item-hd img {
		width: 100%;
		max-height: 100%;
		vertical-align: top;
		display: block;
		border: none;
		margin-top: 6upx;
	}
	.aui-well-item-bd {
		-webkit-box-flex: 1;
		-webkit-flex: 1;
		flex: 1;
		min-width: 0;
	}
	.aui-well-item-bd h3 {
		position: relative;
		/* padding-left: 20px; */
		font-weight: normal;
		padding-bottom: 0upx;
		text-align: left;
		font-size: 32upx;
		font-family: PingFangSC-Regular, PingFangSC;
		color: rgba(59, 59, 59, 1);
	}
	.aui-well-item-fr {
		text-align: right;
		padding-right: 30upx;
		position: relative;
		font-size: 28upx;
		font-family: PingFangSC-Medium, PingFangSC;
		color: rgba(238, 44, 44, 1);
	}
	.aui-mail-product {
		background: #FFFFFF;
		padding: 20upx;
		position: relative;
		overflow: hidden;
	}
	.aui-mail-product-item {
		/* padding: 15px; */
		position: relative;
		display: -webkit-box;
		display: -webkit-flex;
		display: flex;
		-webkit-box-align: center;
		-webkit-align-items: center;
		align-items: center;
	}
	.aui-mail-product-item-hd {
		margin-right: .8em;
		width: 140upx;
		height: 140upx;
		line-height: 140upx;
		text-align: center;
	}
	.aui-mail-product-item-hd img {
		width: 100%;
		max-height: 100%;
		vertical-align: top;
	}
	.aui-mail-product-item-bd {
		-webkit-box-flex: 1;
		-webkit-flex: 1;
		flex: 1;
		min-width: 0;
	}
	.aui-mail-product-item-bd p {
		width: 80%;
		line-height: 1.4;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 3;
		font-size: 28upx;
		font-family: PingFangSC-Medium, PingFangSC;
		color: rgba(0, 0, 0, 1)
	}
	.money {
		font-size: 28upx;
		font-family: PingFangSC-Light, PingFangSC;
		color: rgba(0, 0, 0, 1);
	}
	.aui-mail-payment {
		padding: 20upx 30upx;
		position: relative;
		overflow: hidden;
		display: block;
		font-size: 28upx;
		font-family: PingFangSC-Regular, PingFangSC;
		color: rgba(59, 59, 59, 1);
		width: 100%;
	}
	.aui-mail-payment p em {
		font-style: normal;

	}
	.aui-mail-payment p i {
		font-size: 1.3rem;
		font-style: normal;

	}
	.yunfai {
		float: right;
		
		width: 40%;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		font-size: 22upx;
		font-family: PingFangSC-Regular, PingFangSC;
		color: rgba(140, 140, 140, 1);
	}
	.tou {
		width: 100%;
		height: 98upx;
		background: #F5F5F5;
	}
	.aui-mail-button {
		overflow: hidden;
		width: 90%;
		height: 84upx;
		background: rgba(81, 134, 238, 1);
		border-radius: 10upx;
		/* margin-top: 14upx; */
		margin-left: 5%;
		text-align: center;
		padding-top: 17upx;
	}
	.aui-mail-button a {
		font-size: 36upx;
		font-family: PingFangSC-Regular, PingFangSC;
		color: rgba(255, 255, 255, 1);
		padding-top: 20upx;
		line-height: 50%;
	}
	.aui-mail-button .aui-df-color {
		color: #333;
		border: 2upx solid #ddd;
	}
	.quxiao {
		width: 142upx;
		height: 54upx;
		border-radius: 8upx;
		border: 2upx solid rgba(206, 206, 206, 1);

		font-size: 26upx;
		font-family: PingFangSC-Regular, PingFangSC;

		color: rgba(82, 82, 82, 1);
		text-align: center;
		line-height: 50upx;
		margin-top: 19upx;
		margin-left: 578upx;
	}

	.tiao {
		width: 100%;
		height: 2upx;
		background: #E9E9EC;
		margin-top: 20upx;
	}

	.hd {
		display: none;
	}
</style>
